package com.java.jiuyang.commons.controller;


import com.github.pagehelper.PageInfo;
import com.java.jiuyang.commons.entity.terminal.SysTerminal;
import com.java.jiuyang.commons.entity.terminal.SysUser;
import com.java.jiuyang.commons.service.SysTerminalManagerService;
import com.java.jiuyang.commons.service.SysTerminalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "终端基础信息")
@Controller
@RequestMapping("/sysTerminal")
public class SysTerminalController  {

    @Autowired
    private SysTerminalService service;

    @Autowired
    private SysTerminalManagerService sysTerminalManagerService;

    /**
     * 测试id三表映射查对象集合
     */
    @GetMapping("/selectTerminalList")
    @ResponseBody
    public List<SysTerminal> test(@Param("id")String id){
        System.out.println(service.testTerminal(id));
        return service.testTerminal(id);
    }



    /***
     * @Description 终端设备列表展示
     * @author Fu Hao on 2019/10/22 0022 下午 1:19
     * @param  data  description
     * @return
     **/
    @ApiOperation(value = "终端设备列表展示")
    @GetMapping("/selectTerminalList")
    @ResponseBody
    public void selectTerminalList(@Param("page") Integer page,
                                     @Param("size") Integer size,
                                     @Param("terminal") SysTerminal sysTerminal){
        PageInfo pageInfo=service.selectTerminalList(page,size,sysTerminal);
        /*return ResultGenerator.genSuccessResult(RestRes.table(pageInfo));*/
    }

    /**
       * @return
       * @Description 终端店主基础信息只需要店主信息即可
       *              id：终端设备id
       * @author Fu Hao on 2019/10/15 0015 下午 4:29
    */
    @ApiOperation(value = "终端基础信息详情查询")
    @GetMapping("/findTerminal")
    @ResponseBody
    public void findTerminal(@Param("id") String id){
        /*if (id.isEmpty()){
            return ResultGenerator.genFailResult();
        }
        System.out.println(service.findTerminal(id));*/
        System.out.println(service.findTerminal(id));
    }




    @ApiOperation(value = "终端店主详情")
    @GetMapping("/findManager")
    @ResponseBody
    public void findManager(@Param("id")String id){

       /* if (id.isEmpty()){
            return ResultGenerator.genFailResult();
        }*/
        System.out.println(sysTerminalManagerService.findManager(id));
        sysTerminalManagerService.findManager(id);

    }



    /**
     * No such property: code for class: Script1 description
     * @return
     * @Description 终端店主信息删除
     * @author Fu Hao on 2019/10/16 0016 上午 9:29
     */
    @ApiOperation(value = "终端店主信息删除")
    @DeleteMapping("/delTerminalById")
    public void delTerminalById(@Param("id") String id){
        /*if (StringUtils.isEmpty(id)){
            return ResultGenerator.genFailResult();
        }*/
        sysTerminalManagerService.delTerminalById(id);
    }

    /**
       * No such property: code for class: Script1 description
       * @return
       * @Description 终端店主信息修改 id：终端表id  userName：用户名  phone：用户电话
       * @author Fu Hao on 2019/10/17 0017 下午 1:20
    */
    @ApiOperation(value = "终端店主信息修改")
    @PutMapping("/updTerminalManager")
    public void updTerminalManager(@RequestParam("id") String id
                                     ,@RequestParam("userName") String userName
                                     ,@RequestParam("phone") String phone){
        sysTerminalManagerService.updTerminalManager(id,userName,phone);
        //return ResultGenerator.genSuccessResult();
    }

    /**
     *  terminalid：设备id  sysUser用户   id:终端设备主键id
     * @return
     * @Description 终端店主信息插入/添加
     * @author Fu Hao on 2019/10/15 0015 下午 6:14
     */
    @ApiOperation(value = "终端店主信息插入")
    @PutMapping("/insertTerminal")
    @ResponseBody
    public void insertTerminal(@Param("terminalId") String terminalId,
                                 @Param("id") String id,
                                 SysUser sysUser){
        sysTerminalManagerService.insertTerminal(id,terminalId,sysUser);

    }
    /***
     * @Description 终端基础信息保存/
     * @author Fu Hao on 2019/10/18 0018 上午 10:58
     * @param
     * @return
     **/
    @ApiOperation(value = "终端基础信息保存")
    @PutMapping("/saveTerminal")
    @ResponseBody
    public void saveTerminal(@RequestBody SysTerminal sysTerminal){
        service.saveTerminal(sysTerminal);
    }





}